package com.agritech.state;

import com.agritech.machine.AgriculturalMachineContext;

public class RunningState implements MachineState {
    @Override
    public void start(AgriculturalMachineContext machine) {
        System.out.println("农机 [" + machine.getMachineId() + "] 已经是运行状态。");
    }

    @Override
    public void stop(AgriculturalMachineContext machine) {
        System.out.println("农机 [" + machine.getMachineId() + "] 从运行状态停止中...");
        machine.setState(new IdleState());
    }

    @Override
    public void work(AgriculturalMachineContext machine) {
        if (machine.getFuelLevel() < 10) {
            System.out.println("农机 [" + machine.getMachineId() + "] 油量不足 (" + String.format("%.1f", machine.getFuelLevel()) + "%)，无法开始作业，请加油!");
            // 实际应用中可能自动切换到低油量状态或发出警报
            return;
        }
        System.out.println("农机 [" + machine.getMachineId() + "] 从运行状态开始作业...");
        machine.setState(new WorkingState());
        machine.setFuelLevel(machine.getFuelLevel() - 5); // 作业准备消耗油量
    }

    @Override
    public void fix(AgriculturalMachineContext machine) {
        System.out.println("农机 [" + machine.getMachineId() + "] 正在运行，无法进行检修，请先停止。");
    }

    @Override
    public String getStateName() {
        return "运行中";
    }
}